<template>
    <view class="page">
        <view class="page-head">
            <statusBar></statusBar>
            <view style="display: grid; grid-template-columns: repeat(3, 1fr); align-items: center;">
                <image src="/static/images/logo.png" style="width: 138rpx;height: 40rpx;margin-left: 20rpx;"></image>
                <view></view>
                <view></view>
            </view>

        </view>
        <view class="head-polyfill"></view>
        <view class="page-head-title">
            <image src="/static/images/rhwsbg.png" mode="widthFix" class="img" />
        </view>
        <view class="body">
            <view class="page-title">
                <view class="bd">公众号文章</view>
                <view class="ft" @click="onClickMoreArticle">
                    更多
                    <image :src="imgBaseUrlV2 + 'arrow.png'" mode="widthFix" class="arrow" />
                </view>
            </view>

            <scroll-view :scroll-x="true" class="article-scroll-x" v-if="officialAccountArticle.length">
                <view :id="'t' + item.id" class="item" v-for="(item, index) in officialAccountArticle" :key="item.id"
                    @click="onClickArticle(item, index)">
                    <view class="thumb" :style="{ backgroundImage: `url(${item.url})` }">
                    </view>

                    <view class="title">
                        {{ item.title }}
                    </view>
                    <view class="desc">
                        <view>
                            {{item.read_num}}看过
                        </view>
                        <view>{{ item.create_time}}
                        </view>
                    </view>
                </view>
            </scroll-view>
        </view>
    </view>
</template>

<script>
    import {
        getArticleList,
    } from "@/common/api/service-provider.js";
    import {
        stringToJSON,
        debounce,
        throttle
    } from "@/utils";
    import viewModule from "@/common/mixins/view-module";
    import {
        mapState
    } from "vuex";
    import {
        imgBaseUrlV2
    } from "@/common/config";
    import statusBar from "@/components/public/status-bar/status-bar";
    const system = uni.getSystemInfoSync();
    let statusBarHeight = system.statusBarHeight;
    // #ifdef MP-WEIXIN
    let custom = uni.getMenuButtonBoundingClientRect();
    statusBarHeight = custom.top;
    // #endif
    export default {
        mixins: [viewModule],
        components: {
            statusBar,
        },
        computed: {
            ...mapState("User", ["userInfo"]),
        },
        data() {
            return {
                imgBaseUrlV2,
                statusBarHeight,
                baseUrl: "",
                showSkeleton: false,
                pageHeadStyle: {
                    // backgroundColor: "rgb(63 ,125, 255)",
                },
                serviceProviders: [],
                typeIndex: 0,
                orders: [{
                        id: 1,
                        name: "按评分",
                    },
                    {
                        id: 2,
                        name: "服务量",
                    },
                ],
                services: [

                ],
                typeOptions2: [{
                    label: "类型",
                    value: "",
                }, ],
                mixinViewOptions: {
                    getURL: "/getServiceCase",
                    isPage: true,
                    isShowLoading: false,
                    reachBottom: false,
                    createdIsNeed: false,
                    pullDown: false,
                },
                dataForm: {
                    order: "",
                    type: 1,
                },
                officialAccountArticle: []
            };
        },
        mounted() {
            this.initData();
        },
        methods: {
            getArticleList() {
                getArticleList({
                    page: 1,
                    limit: 5
                }).then((res) => {
                    console.log(res.data)
                    this.officialAccountArticle = res.data
                })
            },
            fetchComplete(err, data = [], res = {}) {
                console.log(data, "?data");
                return data.map((i) => {
                    let img_url = stringToJSON(i.img_url);
                    let thumb = "";
                    if (Array.isArray(img_url) && img_url.length) {
                        thumb = img_url[0].url || img_url[0];
                    }
                    return {
                        ...i,
                        img_url,
                        thumb,
                    };
                });
            },
            async pullDownRefresh() {
                await this.initData();
                uni.$emit("stopPullDownRefresh");
            },
            onClickArticle(item, index) {
                this.$Router.push({
                    path: "/pages/maintenance/articleDetail",
                    query: {
                        id: item.id,
                    },
                });
            },
            async initData() {
                uni.$emit("showLoading");
                this.loadingFinish = false;
                await Promise.all([
                        this.getDataList(),
                        this.getArticleList(),
                    ])
                    .then((res) => {})
                    .catch((err) => {});

                uni.$emit("hideLoading");
                this.loadingFinish = true;
            },

            reachBottom() {},
            onScroll: throttle(function(e) {
                let scrollTop = e.scrollTop;
                let opacity = 0;
                if (scrollTop >= 50) {
                    if (scrollTop > 80) {
                        scrollTop = 80;
                    }
                    opacity = (scrollTop - 50) / 30;
                    if (opacity > 1) {
                        opacity = 1;
                    }
                }
                // this.pageHeadStyle.backgroundColor = `rgba(63 ,125, 255, ${opacity})`;
            }, 20),
            onClickMoreArticle() {
                this.$Router.push({
                    path: "/pages/maintenance/articleIndex",
                });
            },
        },
    };
</script>

<style lang="stylus" scoped>
    @import '~@/common/stylus/variable';
    @import '~@/common/stylus/mixins';

    .page {
        display: flex;
        flex-direction: column;
        height: calc(100vh - var(--window-top) - 100rpx);
        background-color: #fff;
        overflow: hidden;
    }

    .page-head-title {
        // position: fixed;
        z-index: 3;
        width: 100%;
        height: 440rpx;

        >.img {
            display: block;
            width: 100%;
            height: 440rpx;
        }

        left: 0;
        top: 0;
    }

    .page-head {
        position: fixed;
        z-index: 998;
        width: 100%;
        line-height: 64rpx;
        left: 0;
        top: 0;
        text-align: center;
        font-size: 36rpx;
        font-family: PingFangSC-Regular, PingFang SC;
        transition: all 0.3s;
        color: #fff;
        padding-bottom: 12rpx;
        /* #ifdef H5 */
        line-height: 88rpx;
        padding-bottom: 0;
        /* #endif */
    }

    .head-polyfill {
        // height: calc(100rpx + var(--status-bar-height) + var(--window-top));
        // height: 440rpx;
    }

    .body {
        position: relative;
        flex: 1;
        z-index: 4;
        padding: 20rpx 0 170rpx;
        // margin-top: 320rpx;
        background: #1A3156;
        border-radius: 24rpx 24rpx 0 0;
        overflow: auto;
        margin-top: -40rpx;
    }

    .page-title {
        position: relative;
        display: flex;
        align-items: center;
        padding: 16rpx;

        // &:after {
        //   position: absolute;
        //   content: '';
        //   width: 4rpx;
        //   height: 36rpx;
        //   background: #3F7DFF;
        //   left: 0;
        //   top: 24rpx;
        // }

        >.bd {
            flex: 1;
            font-size: 36rpx;
            line-height: 52rpx;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: bold;
            color: #fff;
            text-indent: 8rpx;
        }

        >.ft {
            display: flex;
            flex: 0 0 auto;
            align-items: center;
            font-size: 28rpx;
            line-height: 52rpx;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #fff;

            >.arrow {
                display: block;
                width: 32rpx;
                height: 32rpx;
                margin-left: 8rpx;
                margin-bottom: 2rpx;
            }
        }
    }

    .article-scroll-x {
        width: 100%;
        height: 370rpx;
        white-space: nowrap;
        padding: 20rpx 0;
        margin-bottom: 20rpx;

        .item {
            display: inline-block;
            width: 320rpx;
            height: 420rpx;
            background: #3F5270;
            border-radius: 4rpx;
            white-space: normal;
            overflow: hidden;
            margin-left: 24rpx;

            &:last-child {
                margin-right: 24rpx;
            }

            >.thumb {
                width: 320rpx;
                height: 220rpx;
                background-size: cover;
                margin-bottom: 4rpx;
            }

            >.title {
                width: 280rpx;
                height: 70rpx;
                font-size: 24rpx;
                flex-wrap: wrap;
                color: white;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: bold;
                margin: 20rpx 20rpx;
                /* 多行文本省略样式 */
                display: -webkit-box;
                -webkit-box-orient: vertical;
                -webkit-line-clamp: 2;
                overflow: hidden;
                text-overflow: ellipsis;
            }

            >.desc {
                width: 320rpx;
                height: 24rpx;
                font-size: 24rpx;
                color: #fff;
                margin-top: 10rpx;
                display: flex;
                justify-content: space-between;
                align-items: center;
                padding: 0 20rpx
            }
        }

    }

    .scroll-x {
        width: 100%;
        height: 420rpx;
        white-space: nowrap;
        padding: 20rpx 0;
        margin-bottom: 20rpx;

        .item {
            display: inline-block;
            width: 320rpx;
            height: 420rpx;
            background: #3F5270;
            border-radius: 4rpx;
            white-space: normal;
            overflow: hidden;
            margin-left: 24rpx;

            &:last-child {
                margin-right: 24rpx;
            }

            >.thumb {
                width: 320rpx;
                height: 220rpx;
                background-size: cover;
                margin-bottom: 4rpx;
            }

            >.title,
            >.desc {
                padding: 0 20rpx;
            }

            >.title {
                font-size: 32rpx;
                color: color-white;
                line-height: 50rpx;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: bold;
                no-wrap();
            }

            >.desc {
                font-size: 24rpx;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: color-white;
                line-height: 36rpx;
                no-wraps(2);
                margin-bottom: 10rpx;
                margin-top: 4rpx;
                text-align: justify;
            }
        }
    }

    .service-providers {
        .service-provider {
            display: flex;
            flex-direction: row;
            border-radius: 10rpx;
            margin: 0 24rpx;
            padding: 20rpx 0;
            border-bottom: 1rpx solid rgba(216, 216, 216, 1);

            &:last-child {
                margin-bottom: 0;
                border-bottom: none;
            }

            .service-provider-cover {
                display: block;
                width: 160rpx;
                height: 160rpx;
                margin-top: 10rpx;
            }

            .service-provider-main {
                flex: 1;
                padding-left: 36rpx;

                .title-view {
                    display: flex;
                    flex-direction: row;
                    margin-bottom: 4rpx;

                    .left {
                        flex: 1;

                        .title {
                            font-size: 32rpx;
                            line-height: 52rpx;
                            font-weight: 700;
                            color: #fff;
                            font-family: PingFangSC-Regular, PingFang SC;
                            font-weight: bold;
                            margin-right: 20rpx;
                        }

                        >.tag {
                            display: inline-block;
                            height: 40rpx;
                            line-height: 40rpx;
                            background: #3F5270;
                            border-radius: 4rpx;
                            font-size: 24rpx;
                            font-family: PingFangSC-Regular, PingFang SC;
                            font-weight: 400;
                            color: #FEBE3D;
                            margin-right: 20rpx;
                        }
                    }
                }

                .second-line {
                    display: flex;
                    font-size: 22rpx;
                    line-height: 50rpx;

                    .rate-view {
                        display: flex;
                        align-items: center;

                        .star {
                            display: inline-block;
                            width: 26rpx;
                            margin-bottom: 2rpx;
                        }

                        .rate {
                            padding-left: 18rpx;
                            font-size: 28rpx;
                            font-family: PingFangSC-Regular, PingFang SC;
                            font-weight: 400;
                            color: #FFBB00;
                        }
                    }

                    .order-num {
                        padding-left: 20rpx;
                        font-size: 28rpx;
                        font-family: PingFangSC-Regular, PingFang SC;
                        font-weight: 400;
                        color: #fff;
                    }
                }
            }

            .location-view {
                display: flex;
                line-height: 60rpx;
                flex: 1;

                .location-icon {
                    width: 26rpx;
                    flex: 0 0 26rpx;
                    vertical-align: middle;
                    margin-top: 8rpx;
                }

                .location {
                    flex: 1;
                    padding-left: 10rpx;
                    color: #fff;
                    font-size: 28rpx;
                    line-height: 42rpx;
                    font-family: PingFangSC-Regular, PingFang SC;
                    font-weight: 400;
                    no-wrap();
                    width: 0;
                }
            }
        }
    }

    .filter {
        display: flex;
        padding: 0 24rpx;
        margin: 20rpx 0;

        >.orders {
            display: flex;
            flex: 1;
            flex-wrap: wrap;

            >.item {
                height: 46rpx;
                line-height: 46rpx;
                border-radius: 6rpx;
                border: 1rpx solid#fff;
                color: #fff;
                font-size: 28rpx;
                padding: 0 14rpx;
                margin-right: 18rpx;
                transition: all 0.3s;

                &:last-child {
                    margin-right: 0;
                }

                &.active {
                    color: #fff;
                    background-color: #3F5270;
                    border: none;
                }
            }
        }

        >.type {
            .picker-type {
                display: flex;
                font-size: 28rpx;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #fff;
                align-items: center;

                .image {
                    display: block;
                    width: 32rpx;
                    height: 32rpx;
                    flex: 0 0 32rpx;
                    transform: rotate(90deg);
                    margin-left: 12rpx;
                }
            }

            flex: 0 0 auto;
        }
    }
</style>